/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.upf.grupE.impl;


import edu.upf.grupE.Entities.Picture;
import edu.upf.grupE.Listener;
import javax.swing.ImageIcon;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;

/**
 *
 * @author xday666
 */
public class searchResultListener implements Listener {
/*this class implements the listener which will be prepared to understand the searchResult
     Packets.*/
    final IM im;

    /**
     * Constructor.
     * @param instancem IM instancem
     */
    public searchResultListener(final IM instancem) {
        im = instancem;
    }



    /**
     *we only work with the packets that are Messages.
     *To be sure that the information that arrives to this listener is correct, we
     *print it into the Text Box
     * @param packet Packet packet
     */
    public final void processPacket(final Packet packet) {
        if (packet instanceof Message) {

            System.out.println("Arriba algo");
            Message msg = (Message) packet;

            Picture searchResultPic = (Picture) msg.getProperty("searchResultPic");



            im.el.recivedResult(searchResultPic, msg.getFrom());
            //Systema temporal de muestra resultados obtenidos
//            im.addText(msg.getFrom() , "Resultados recibidos:");
//            im.addText(msg.getFrom() , "Pictureid: " + searchResultPic.getId());
//            im.addText(msg.getFrom() , "Descripcion: " + searchResultPic.getTextDescription().getDescription());
        }
    }
}
